前面的設置中文字體,發現不能在heroku上使用
這邊我用matplotlib.font_manager 的 FontProperties直接使用指定路徑的字體來代替
fontname='font/Arial Unicode MS.ttf'
for key, cell in tab.get_celld().items():
row, col = key
if row >= 0 and col >= 0:
cell.set_text_props(fontproperties=FontProperties(fname=fontname))
修改後
if(event.message.text[:3:]=="團購" and rights[2]): #view right
cursor = conn.cursor()
cursor.execute(f"SELECT keyword,name,quantity FROM group_buying_user NATURAL JOIN group_buying_message order by keyword;")
users = cursor.fetchall()
cursor.close()
fig, ax =plt.subplots(1,1)
data=[]
color=[]
color_list = ["#89C6C6","#A889C6","#C68989","#A8C689","#C07BC0","#C6C689"]
category=''
i=0
column_labels=['keyword','name','quantity']
for user in users:
if not category==user[0]:
if i==len(color_list)-1:
i=0
else:
i=i+1
color.append([color_list[i],color_list[i],color_list[i]])
category=user[0]
data.append([user[0],user[1],user[2]])
ax.axis('tight')
ax.axis('off')
tab=ax.table(cellText=data,colColours=["#DDDDDD"]*3,cellColours=color,colLabels=column_labels,cellLoc='center',loc="center")
fontname='font/Arial Unicode MS.ttf'
for key, cell in tab.get_celld().items():
row, col = key
if row >= 0 and col >= 0:
cell.set_text_props(fontproperties=FontProperties(fname=fontname))
plt.savefig('img/table.png',dpi=200)
CLIENT_ID='ceda715b6015fcb'
PATH = "img/table.png"
im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(PATH, title="iThome-2021")
print(uploaded_image.link)
message = ImageSendMessage(
original_content_url=uploaded_image.link,
preview_image_url=uploaded_image.link
)
line_bot_api.reply_message(event.reply_token,message)
更新數量